package com.holly.unit.deform.designer.core.table;

import cn.hutool.core.util.StrUtil;
import com.holly.unit.deform.designer.context.FormDesignerDbContext;
import com.holly.unit.deform.designer.service.DmlService;
import com.holly.unit.deform.designer.util.DMLUtil;

/**
 * 类描述: 数据操控语言语句执行器
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/8/3 9:34
 */
public class DmlExecutor {
    private static DmlService dmlService = FormDesignerDbContext.dmlService();

    private DmlExecutor() {
        throw new UnsupportedOperationException("DmlExecutor类无法实例化");
    }

    public static void execute(String sql) {

        if (StrUtil.isEmpty(sql)) {
            return;
        }

        // 插入表数据
        if (DMLUtil.isInsert(sql)) {
            dmlService.insert(sql);
        }

        // 修改表数据
        if (DMLUtil.isUpdate(sql)) {
            dmlService.update(sql);
        }

        // 删除表数据
        if (DMLUtil.isDelete(sql)) {
            dmlService.delete(sql);
        }
    }
}
